package com.article.controller;

import com.apis.ApAuthor.AdarticleApi;
import com.article.mapper.ArticleMapper;
import com.article.service.ApAuthorService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.model.atri.pojos.ApArticle;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;
import com.usian.model.user.pojos.ApAuthor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/article/api/v1")
public class ArticleController implements AdarticleApi {

    @Autowired
    private ApAuthorService apAuthorService;

    @Resource
    ArticleMapper articleMapper;

    @Resource
    private com.article.service.ArticleServicetu ArticleServicetu;


    @GetMapping("/article/api/v1/findByIdauthor")
    public ApAuthor findByIdauthor (@PathVariable("id") Integer id){
        return apAuthorService.getById(id);
    }


    @PostMapping("/findById/{id}")
    @Override
    public ApAuthor findById(@PathVariable("id") Integer id) {
        return apAuthorService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getUserId,id));
    }

    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody ApAuthor apAuthor) {
        apAuthorService.save(apAuthor);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @PostMapping("/saveArticle")
    @Override
    public ApArticle saveArticle(@RequestBody ApArticle apArticle){
        System.out.println( ArticleServicetu.save(apArticle));
        System.out.println(apArticle);
        return apArticle ;
    }


    @GetMapping("/findByIdapauthor")
    @Override
    public ApAuthor  findByIdapauthor(@RequestParam Integer id) {
        return articleMapper.selectById(id);
//        return articleService.getOne(Wrappers.<ApAuthor>lambdaQuery().eq(ApAuthor::getId,id));
    }







}
